#include "cwmp/model.h"
#include "data_model.h"
#include "cwmp_module.h"
#include "InternetGatewayDevice/InternetGatewayDevice.c"


model_func_t ModelFunction[] =
{
    //InternetGatewayDevice.
    {"cpe_get_igd_devicesummary", cpe_get_igd_devicesummary},
    {"cpe_get_igd_lan_device_number_of_entries", cpe_get_igd_lan_device_number_of_entries},
    {"cpe_get_igd_wan_device_number_of_entries", cpe_get_igd_wan_device_number_of_entries},
    //InternetGatewayDevice.DeviceInfo.
    {"get_igd_di_manufacturer", cpe_get_igd_di_manufacturer},
    {"get_igd_di_manufactureroui", cpe_get_igd_di_manufactureroui},
    {"get_igd_di_productclass", cpe_get_igd_di_productclass},
    {"get_igd_di_serialnumber", cpe_get_igd_di_serialnumber},
    {"get_igd_di_specversion", cpe_get_igd_di_specversion},
    {"get_igd_di_hardwareversion", cpe_get_igd_di_hardwareversion},
    {"get_igd_di_softwareversion", cpe_get_igd_di_softwareversion},
    {"get_igd_di_provisioningcode", cpe_get_igd_di_provisioningcode},
    {"set_igd_di_softwareversion", cpe_set_igd_di_softwareversion},
    {"set_igd_di_hardwareversion", cpe_set_igd_di_hardwareversion},	

    //InternetGatewayDevice.DeviceInfo.VendorConfigFile.	
    {"get_igd_di_vc_name", cpe_get_igd_di_vc_name},
    {"get_igd_di_vc_version", cpe_get_igd_di_vc_version},
    {"get_igd_di_vc_date", cpe_get_igd_di_vc_date},
    {"get_igd_di_vc_description", cpe_get_igd_di_vc_description},    

    //InternetGatewayDevice.ManagementServer.
    {"get_igd_ms_username", cpe_get_igd_ms_username},
    {"set_igd_ms_username", cpe_set_igd_ms_username},    
    {"get_igd_ms_password", cpe_get_igd_ms_password},
    {"set_igd_ms_password", cpe_set_igd_ms_password},   
    {"get_igd_ms_url", cpe_get_igd_ms_url},
    {"set_igd_ms_url", cpe_set_igd_ms_url},    
    {"get_igd_ms_connectionrequesturl", cpe_get_igd_ms_connectionrequesturl},
    {"get_igd_ms_connectionrequestusername", cpe_get_igd_ms_connectionrequestusername},
    {"set_igd_ms_connectionrequestusername", cpe_set_igd_ms_connectionrequestusername},    
    {"get_igd_ms_connectionrequestpassword", cpe_get_igd_ms_connectionrequestpassword},
    {"set_igd_ms_connectionrequestpassword", cpe_set_igd_ms_connectionrequestpassword},
    {"get_igd_ms_STUNEnable", cpe_get_igd_ms_STUNEnable},
    {"set_igd_ms_STUNEnable", cpe_set_igd_ms_STUNEnable},
    {"get_igd_ms_parameterkey", cpe_get_igd_ms_parameterkey},
    {"set_igd_ms_parameterkey", cpe_set_igd_ms_parameterkey},  
    {"get_igd_ms_stunserveraddress", cpe_get_igd_ms_stunserveraddress},
    {"set_igd_ms_stunserveraddress", cpe_set_igd_ms_stunserveraddress},
    {"get_igd_ms_stunserverport", cpe_get_igd_ms_stunserverport},
    {"set_igd_ms_stunserverport", cpe_set_igd_ms_stunserverport},
    {"get_igd_ms_stunusername", cpe_get_igd_ms_stunusername},
    {"set_igd_ms_stunusername", cpe_set_igd_ms_stunusername},
    {"get_igd_ms_stunpassword", cpe_get_igd_ms_stunpassword},
    {"set_igd_ms_stunpassword", cpe_set_igd_ms_stunpassword},
	{"get_igd_ms_stunmaximumkeepaliveperiod", cpe_get_igd_ms_stunmaximumkeepaliveperiod},
	{"set_igd_ms_stunmaximumkeepaliveperiod", cpe_set_igd_ms_stunmaximumkeepaliveperiod},
	{"get_igd_ms_stunminimumkeepaliveperiod", cpe_get_igd_ms_stunminimumkeepaliveperiod},
	{"set_igd_ms_stunminimumkeepaliveperiod", cpe_set_igd_ms_stunminimumkeepaliveperiod},
	{"get_igd_ms_natdetected", cpe_get_igd_ms_natdetected},
	{"set_igd_ms_natdetected", cpe_set_igd_ms_natdetected},
    {"get_igd_ms_PeriodicInformEnable", cpe_get_igd_ms_PeriodicInformEnable},
    {"set_igd_ms_PeriodicInformEnable", cpe_set_igd_ms_PeriodicInformEnable},
    {"get_igd_ms_PeriodicInformInterval", cpe_get_igd_ms_PeriodicInformInterval},
    {"set_igd_ms_PeriodicInformInterval", cpe_set_igd_ms_PeriodicInformInterval},	    

    {"add_igd_wanpppconnection", cpe_add_igd_wanpppconnection},
    
    {"del_igd_wanconnectiondevice", cpe_del_igd_wanconnectiondevice},

	{"refresh_igd_landevice", cpe_refresh_igd_landevice},

	//InternetGatewayDevice.User
	{"get_user", cpe_get_user},
	{"get_username", cpe_get_username},
	{"get_password", cpe_get_password},
	{"set_username", cpe_set_username},
	{"set_password", cpe_set_password},
	//InternetGatewayDevice.Time
	{"get_igd_time_ntpserver0", cpe_get_igd_time_ntpserver0},
    {"get_igd_time_ntpserver1", cpe_get_igd_time_ntpserver1},
    {"get_igd_time_ntpserver2", cpe_get_igd_time_ntpserver2},
    {"set_igd_time_ntpserver0", cpe_set_igd_time_ntpserver0},
    {"set_igd_time_ntpserver1", cpe_set_igd_time_ntpserver1},
    {"set_igd_time_ntpserver2", cpe_set_igd_time_ntpserver2},    
    {"get_igd_time_currentlocaltime", cpe_get_igd_time_currentlocaltime},
    {"get_igd_time_localtimezone", cpe_get_igd_time_localtimezone},
    {"get_igd_time_localtimezonename", cpe_get_igd_time_localtimezonename},
	//InternetGatewayDevice.Time
	{"get_igd_ping_success", cpe_get_igd_ping_success},
    {"get_igd_ping_failure", cpe_get_igd_ping_failure},
    {"get_igd_ping_average", cpe_get_igd_ping_average},
    {"get_igd_ping_minimum", cpe_get_igd_ping_minimum},
    {"get_igd_ping_maximum", cpe_get_igd_ping_maximum},
    {"set_igd_ping_state", cpe_set_igd_ping_state},
    {"set_igd_ping_dscp", cpe_set_igd_ping_dscp},
    {"set_igd_ping_host", cpe_set_igd_ping_host},
    {"set_igd_ping_iface", cpe_set_igd_ping_iface},
    {"set_igd_ping_repeat", cpe_set_igd_ping_repeat},
    {"set_igd_ping_data_size", cpe_set_igd_ping_data_size},
    {"set_igd_ping_timeout", cpe_set_igd_ping_timeout},
    {"get_igd_ping_state", cpe_get_igd_ping_state},
    {"get_igd_ping_dscp", cpe_get_igd_ping_dscp},
    {"get_igd_ping_host", cpe_get_igd_ping_host},
    {"get_igd_ping_iface", cpe_get_igd_ping_iface},
    {"get_igd_ping_repeat", cpe_get_igd_ping_repeat},
    {"get_igd_ping_data_size", cpe_get_igd_ping_data_size},
    {"get_igd_ping_timeout", cpe_get_igd_ping_timeout},
	//InternetGatewayDevice.TraceRouteDiagnostics
	{"reload_trd", cpe_reload_trd},
    {"get_trd_state", cpe_get_trd_state},
    {"set_trd_state", cpe_set_trd_state},
    {"get_trd_iface", cpe_get_trd_iface},
    {"set_trd_iface", cpe_set_trd_iface},
    {"get_trd_host", cpe_get_trd_host},
    {"set_trd_host", cpe_set_trd_host},
    {"get_trd_tries", cpe_get_trd_tries},
    {"set_trd_tries", cpe_set_trd_tries},
    {"get_trd_timeout", cpe_get_trd_timeout},
    {"set_trd_timeout", cpe_set_trd_timeout},
    {"get_trd_dbs", cpe_get_trd_dbs},
    {"set_trd_dbs", cpe_set_trd_dbs},
    {"get_trd_dscp", cpe_get_trd_dscp},
    {"set_trd_dscp", cpe_set_trd_dscp},
    {"get_trd_mhc", cpe_get_trd_mhc},
    {"set_trd_mhc", cpe_set_trd_mhc},
    {"get_trd_hop", cpe_get_trd_hop},
    {"get_trd_hop_count", cpe_get_trd_hop_count},
    {"get_trd_response", cpe_get_trd_response},
	//InternetGatewayDevice.WANDevice
	{"refresh_igd_wandevice", cpe_refresh_igd_wandevice},

	//InternetGatewayDevice.WANDevice.WANConnectionDevice
    {"refresh_igd_wanconnectiondevice", cpe_refresh_igd_wd_wanconnectiondevice},
    {"get_profile_name", cpe_get_profile_name},
	{"get_apn", cpe_get_apn},
	{"get_pdp_type", cpe_get_pdp_type},
	{"get_ppp_auth_type", cpe_get_ppp_auth_type},
	{"get_ppp_username", cpe_get_ppp_username},
	{"get_ppp_passwd", cpe_get_ppp_passwd}, 
	{"get_prefer_dns", cpe_get_prefer_dns},
	{"get_standby_dns", cpe_get_standby_dns},
	{"get_mtu", cpe_get_mtu},
	
	//InternetGatewayDevice.WANDevice.WANConnectionDevice.WANIPConnection
    {"refresh_igd_wanipconnection", cpe_refresh_igd_wd_wcd_wanipconnection},
	{"get_igd_wd_wcd_wic_enable", cpe_get_igd_wd_wcd_wic_enable},
    {"get_igd_wd_wcd_wic_rsrp", cpe_get_igd_wd_wcd_wic_rsrp},
	{"get_igd_wd_wcd_wic_rssi", cpe_get_igd_wd_wcd_wic_rssi},

    //InternetGatewayDevice.WANDevice.COM_WANInterfaceConfig
    {"refresh_igd_wd_comwaninterfaceconfig", cpe_refresh_igd_wd_comwaninterfaceconfig},
	{"get_imei", cpe_get_imei},
    {"get_imsi", cpe_get_imsi},
    {"get_cell_id", cpe_get_cell_id},
    {"get_sinr", cpe_get_sinr},
    {"get_plmn", cpe_get_plmn},
    {"get_tac_code", cpe_get_tac_code},
    {"get_down_rate", cpe_get_down_rate},
    {"get_up_rate", cpe_get_up_rate},
    {"get_band_list", cpe_get_band_list},
    {"set_band_lock", cpe_set_band_lock},
    {"get_neighborhood_pci", cpe_get_neighborhood_pci},
    {"get_neighborhood_rsrp", cpe_get_neighborhood_rsrp},
    {"get_duplexing_mode", cpe_get_duplexing_mode},
    {"get_max_dl_speed", cpe_get_max_dl_speed},
    {"get_max_ul_speed", cpe_get_max_ul_speed},
    {"get_operation_band", cpe_get_operation_band},
    {"get_rsrq", cpe_get_rsrq},
    {"get_cqi", cpe_get_cqi},
    {"get_rank", cpe_get_rank},
    {"get_dlearfcn", cpe_get_dlearfcn},
    
	//InternetGatewayDevice.WANDevice.WANEthernetInterfaceConfig
    {"refresh_igd_wd_wanetherinterfaceconfig", cpe_refresh_igd_wd_wanetherinterfaceconfig},
    {"get_bytes_sent", cpe_get_bytes_sent},
    {"get_bytes_received", cpe_get_bytes_received},
    {"get_packets_sent", cpe_get_packets_sent},
    {"get_packets_received", cpe_get_packets_received},
   
    //InternetGatewayDevice.LANDevice
    {"refresh_igd_landevice", cpe_refresh_igd_landevice},

	//InternetGatewayDevice.Hosts
	{"cpe_refresh_hosts", cpe_refresh_hosts},
    {"cpe_get_hosts_count", cpe_get_hosts_count},
    {"cpe_get_hosts", cpe_get_hosts},
	
	//InternetGatewayDevice.LANDevice.LANHostConfigManagement.IPInterface
	{"get_dhcp_server_enable", cpe_get_dhcp_server_enable},
	{"get_dhcp_start_ip", cpe_get_dhcp_start_ip},
	{"get_dhcp_end_ip", cpe_get_dhcp_end_ip},
	{"get_dhcp_lease_time", cpe_get_dhcp_lease_time},
	{"set_dhcp_server_enable", cpe_set_dhcp_server_enable},
	{"set_dhcp_start_ip", cpe_set_dhcp_start_ip},
	{"set_dhcp_end_ip", cpe_set_dhcp_end_ip},
	{"set_dhcp_lease_time", cpe_set_dhcp_lease_time},
	{"get_domain_name", cpe_get_domain_name},
	{"set_domain_name", cpe_set_domain_name},
	
    {"refresh_igd_ld_lhcm_ipinterface", cpe_refresh_igd_ld_lhcm_ipinterface},

	{"get_igd_ld_lhcm_ipinterfaceipaddress", cpe_get_igd_ld_lhcm_ipinterfaceipaddress},
    {"set_igd_ld_lhcm_ipinterfaceipaddress", cpe_set_igd_ld_lhcm_ipinterfaceipaddress},
    {"get_igd_ld_lhcm_ipinterfacesubnetMask", cpe_get_igd_ld_lhcm_ipinterfacesubnetMask},
    {"set_igd_ld_lhcm_ipinterfacesubnetMask", cpe_set_igd_ld_lhcm_ipinterfacesubnetMask},

    //InternetGatewayDevice.LANDevice.LANHostConfigManagement.DHCPStaticAddress
    {"refresh_igd_ld_lhcm_dhcpstaticaddress", cpe_refresh_igd_ld_lhcm_dhcpstaticaddress},
    
    //InternetGatewayDevice.LANDevice.LANEthernetInterfaceConfig
    {"refresh_igd_ld_lanethernetinterfaceconfig", cpe_refresh_igd_ld_lanethernetinterfaceconfig},
    {"get_lan_bytes_sent", cpe_get_lan_bytes_sent},
    {"get_lan_bytes_received", cpe_get_lan_bytes_received},
    {"get_lan_packets_sent", cpe_get_lan_packets_sent},
    {"get_lan_packets_received", cpe_get_lan_packets_received},

	//InternetGatewayDevice.LANDevice.WLANConfiguration
    {"refresh_igd_ld_wlanconfiguration", cpe_refresh_igd_ld_wlanconfiguration},	
	{"get_igd_ld_wc_enable", cpe_get_igd_ld_wc_enable},
	{"set_igd_ld_wc_enable", cpe_set_igd_ld_wc_enable},
	{"get_igd_ld_wc_bssid", cpe_get_igd_ld_wc_bssid},
	{"get_igd_ld_wc_ssid", cpe_get_igd_ld_wc_ssid},
	{"set_igd_ld_wc_ssid", cpe_set_igd_ld_wc_ssid},
	{"get_igd_ld_wc_channel", cpe_get_igd_ld_wc_channel},
	{"set_igd_ld_wc_channel", cpe_set_igd_ld_wc_channel},
	{"get_igd_ld_wc_autochannel", cpe_get_igd_ld_wc_autochannel},
	{"set_igd_ld_wc_autochannel", cpe_set_igd_ld_wc_autochannel},
	{"get_igd_ld_wc_encryption_mode", cpe_get_igd_ld_wc_encryption_mode},
	{"set_igd_ld_wc_encryption_mode", cpe_set_igd_ld_wc_encryption_mode},
	{"get_igd_ld_wc_bandwidth", cpe_get_igd_ld_wc_bandwidth},
	{"set_igd_ld_wc_bandwidth", cpe_set_igd_ld_wc_bandwidth},
	{"get_igd_ld_wc_psk", cpe_get_igd_ld_wc_psk},
	{"set_igd_ld_wc_psk", cpe_set_igd_ld_wc_psk},
	{"get_wlan_bytes_sent", cpe_get_wlan_bytes_sent},
    {"get_wlan_bytes_received", cpe_get_wlan_bytes_received},
    {"get_wlan_packets_sent", cpe_get_wlan_packets_sent},
    {"get_wlan_packets_received", cpe_get_wlan_packets_received},

    //InternetGatewayDevice.LANDevice.WLANConfiguration.WEPKey
    {"refresh_igd_ld_wc_wepkey", cpe_refresh_igd_ld_wc_wepkey},

    //InternetGatewayDevice.LANDevice.WLANConfiguration.PreSharedKey
    {"refresh_igd_ld_wc_presharekey", cpe_refresh_igd_ld_wc_presharekey},
};

int get_index_after_paramname(parameter_node_t * param, const char * tag_name)
{
    parameter_node_t * parent;
    parameter_node_t * tmp;
    for(parent=param->parent, tmp = param; parent; tmp = parent, parent = parent->parent)
    {
        if(TRstrcmp(parent->name, tag_name) == 0)
        {
             if(is_digit(tmp->name) == 0)
             {
                return TRatoi(tmp->name);   
             }
        }        
    }
    return -1;
}

const char *cwmp_model_ptr_to_func(void *p)
{
    int n = (sizeof(ModelFunction) / sizeof(*ModelFunction));

    if (!p) {
        return "null";
    }

    while (n-- > 0) {
        if (ModelFunction[n].func == p)
            return ModelFunction[n].name;
    }
    return "?";
}


void cwmp_model_load(cwmp_t * cwmp, const char * xmlfile)
{  

    cwmp_model_load_xml(cwmp, xmlfile, ModelFunction, sizeof(ModelFunction)/sizeof(model_func_t));
}


